package com.iplant.mes.controller.sfc;

import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.mes.service.SFCFrockBindService;
import com.iplant.mes.service.po.sfc.SFCStationInterfaceLog;
import com.iplant.mes.service.po.sfc.SFCTaskStartCheck;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 工位最近接口日志
 *
 * @author YouWang·Peng
 * 2024-5-26 10:01:04
 */
@RestController
@RequestMapping("/api/SFCStationInterfaceLog")
public class SFCStationInterfaceLogController extends BasicController<SFCTaskStartCheck> {
    private static final Logger logger = LoggerFactory.getLogger(SFCStationInterfaceLogController.class);

    public SFCStationInterfaceLogController() {
        super(SFCTaskStartCheck.class);
    }

    @Autowired
    SFCFrockBindService mSFCFrockBindService;

    /**
     * 查询工位接口日志
     */
    @GetMapping("/All")
    public Object All(HttpServletRequest request) {
        Object wResult = new Object();
        try {
            BMSEmployee wLoginUser = GetSession(request);

            int wStationID = StringUtils.parseInt(request.getParameter("StationID"));
            String wInterfaceType = StringUtils.parseString(request.getParameter("InterfaceType"));

            ServiceResult<List<SFCStationInterfaceLog>> wServiceResult =
                    mSFCFrockBindService.SFC_QueryStationInterfaceLogAll(wLoginUser, wStationID, wInterfaceType);

            if (StringUtils.isEmpty(wServiceResult.FaultCode)) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, null);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString(), null, null);
        }
        return wResult;
    }
}
